import json
import pymysql

with open('events_202211051645.json', 'r') as jsonfile:
    json_string = json.load(jsonfile)
    event_list = json_string['vscode']
    print(event_list)
# 打开数据库连接
db = pymysql.connect(host='111.47.28.118',
                     user='root',
                     password='kjwx886612',
                     database='os-ecology',
                     port=9989)

# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()

sql = "INSERT INTO `os-ecology`.asp_senti_comment(`creat_at`, `polarity`, `aspect_word`, `sentiment_word`, `repo_name`, `comment`) VALUES (%s, %s, %s, %s, %s, %s)"

# 使用 execute()  方法执行 SQL 查询
try:
    cursor.execute(sql, ('2020-05-15 14:43:20.000', 1, 'windows', 'good', 'vscode', 'good windows'))
    # connection is not autocommit by default. So you must commit to save
    # your changes.
    db.commit()
except:
   # 发生错误时回滚
    db.rollback()

# 关闭数据库连接
db.close()